package com.kuang.login.service;

import com.kuang.login.dao.userDao;
import com.kuang.login.dao.userMysqlDao;
import com.kuang.login.model.User;

import java.util.HashMap;
import java.util.List;

/**
 * Created by 郭浩 on 2020/9/25 21:15
 */
public class userServiceImpl implements userService{
    userDao userdao =  new userMysqlDao();
    @Override
    public int register(User user) {
        return userdao.register(user);
    }

    @Override
    public int login(User user) {
        return userdao.login(user);
    }

    @Override
    public HashMap<String, Object> queryPageUser(int curPage) {
        int pageSize = 2;
        int count = userdao.getUserCount();
        int totalPage = 0;
        if(count % pageSize == 0){
            totalPage = count / pageSize;
        }else {
            totalPage = count / pageSize + 1;
        }
        List<User> users = userdao.queryCurrentPageUser(curPage, pageSize);
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", count);
        map.put("page", totalPage);
        map.put("users", users);
        return map;
    }
}
